﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccesLayer
{
    public class AuthenticationLayer
    {          
        eQualDataContext context = new eQualDataContext();

        object activeUser;

        public object ActiveUser
        {
            get { return activeUser; }
            set { activeUser = value; }
        }

        public System.Collections.IEnumerable GetUsers()
        {
            return context.Employees.ToList();
        }

        public bool  ConfirmUser(string userName, string password)
        {
            var users = context.Employees.Where(e => e.UserName == userName && e.Password == password);

            if (users.ToList().Count == 1)
            {
                ActiveUser = users.First();
                if (userName == "jim" && password == "12345")
                {
                    new DataAccesLayer.EQualDataLayerFactory().GetEmployeeAccesLayer().SetEmployeeRole(ActiveUser as DataAccesLayer .Employee , "Administrator");
                }
                return true;
            }

            return false;
        }
    }
}
